package com.example.springbootdemo;

import com.google.common.base.Supplier;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class LambdaDemo {


    @Test
    public void test(){

        Runnable r= () ->{

            System.out.println("hello wo shi lambda");
        };
        new Thread(r).start();
    }


    @Test
    public void test01(){
        Comparator<Integer> com= (x,y) ->{

            System.out.println("x===="+x+"====y="+y);
            return Integer.compare(x,y);
        };

        int compare = com.compare(5, 3);

        System.out.println(compare);
    }

    @Test
    public void test02(){

        boolean draft = predicateFunction("hnbx_draft11");
        System.out.println(draft);
    }

    boolean predicateFunction(String a){

        Predicate<String> predicate=(str) ->{
            return str.endsWith("_draft");
        };

        return predicate.test(a);
    }

    @Test
    public void test03(){

        People people1=new People();
        people1.setName("kk");
        people1.setAge(90);
        People people2=new People();
        people2.setName("大纲");
        people2.setAge(99);
        List<People> list=new ArrayList<>();
        list.add(people1);
        list.add(people2);

        List<People> collect = list.stream().filter((a) -> {
            return "kk".equals(a.getName());
        }).collect(Collectors.toList());

        System.out.println(list);

        System.out.println(collect);
    }


    @Test
    public void test04(){

       Comparator<Integer> com=Integer ::compare;
        int compare = com.compare(5, 2);
        System.out.println(compare);
    }

    @Test
    public void test05(){
        People people1=new People();
        people1.setName("kk");
        people1.setAge(90);
        People people2=new People();
        people2.setName("大纲");
        people2.setAge(99);
        List<People> list=new ArrayList<>();
        list.add(people1);
        list.add(people2);
        List<String> collect = list.stream().map(People::getName).collect(Collectors.toList());
        System.out.println(collect);
    }

    @Test
    public void test06(){
        People people1=new People();
        people1.setName("kk");
        people1.setAge(90);
        People people2=new People();
        people2.setName("大纲");
        people2.setAge(99);
        List<People> list=new ArrayList<>();
        list.add(people1);
        list.add(people2);
        List<String> collect = list.stream().map( (a) ->{
            return a.getName();
        }).collect(Collectors.toList());
        System.out.println(collect);

    }
}
